//
//  GROrderCommentTableViewCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/26.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GROrderCommentTableViewCell.h"
#import "GRPhotoBrowserVC.h"
@implementation GROrderCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    

    // Initialization code
}

-(void)setCommentModel:(GRCommentModel *)commentModel{
    _commentModel = commentModel;
    self.starView.isGesSelect = NO;
    [self.goodImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.goodsImg] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    self.nameLabel.text = commentModel.goodsName;
    self.specLabel.text = commentModel.specDesc;
    self.starView.score = commentModel.geStarGrade ;
    self.priceLabel.text = [NSString stringWithFormat:@"%.2lf",commentModel.price];
    self.timeLabel.text = commentModel.createTime;
    self.commentContentLabel.text = commentModel.geContent;
    if (commentModel.imgArray.count >0) {
         self.picImageScroller.hidden = NO;
        self.imageHeight.constant = (KscreenWidth-45)/3;
        [self removewViewAllSubViews:self.picImageScroller];
        CGFloat startX = 0;
        CGFloat ImageW = (KscreenWidth-45)/3;
        for (int i = 0 ; i < commentModel.imgArray.count && i< 3; i++) {
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(startX, 0, ImageW, ImageW)];
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.layer.masksToBounds = YES;
            GRCommentImageModel *  imageModel =  commentModel.imgArray[i];
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageModel .geiImg] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
            UITapGestureRecognizer * tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showBigImageView:)];
            [imageView addGestureRecognizer:tapGes];
            imageView.userInteractionEnabled = YES;
            imageView.tag = 1000 +i;
            startX += ImageW +10;
            [self.picImageScroller addSubview:imageView];
        }
        
    }else{
       self.imageHeight.constant = 1;
        self.picImageScroller.hidden = YES;
        
    }

    
}
-(void)showBigImageView:(UITapGestureRecognizer *)tapRecognized{
    UIImageView  * imageView = (UIImageView *)tapRecognized.view;
    if (_delegate && [_delegate respondsToSelector:@selector(seleteImageIndex:imagArr:)]) {
        [_delegate seleteImageIndex:imageView.tag-1000 imagArr:self.commentModel.comentImageArr];
    }


    
}

-(void)removewViewAllSubViews:(UIView *)view{
    for (UIView * subView in view.subviews) {
        [subView removeFromSuperview];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
